/**
 * 
 * 浏览器转换
 * 
 * 2025-10-27 13:43:16
 * 
 */
var user_ButtonFunData = {
    initStart: function (params) {
        var $ = layui.$;
        layui.dropdown.render({
            elem: '.demo-dropdown-base', // 绑定元素选择器，此处指向 class 可同时绑定多个元素
            data: [{
                templet: function (params) {
                    return `<i class="icon Kaultraiconfont Kaultraicon-zhongzhimima"></i>重置密码`
                },
                id: 100
            }, {
                templet: function (params) {
                    return '<i class="icon Kaultraiconfont Kaultraicon-fenpeijiaose"></i>分配角色'
                },
                id: 101
            }, {
                templet: function (params) {
                    return '<i class="icon Kaultraiconfont Kaultraicon-leaseofhouse"></i>分配租户'
                },
                id: 102
            }],
            click: function (obj) {
                alert(JSON.stringify(obj));
            }
        });
    },
    add: function (bussId, type) {
        layer.open({
            id: "formRenderingHtml4",
            type: 2,
            title: '添加用户',
            shadeClose: true,
            shade: [0.6, '#FFF'],
            area: ['700px', '70%'],
            content: './formRendering.html?id=4' // iframe 的 url
        });
    },
    copyAdd: function (bussId, type) {
        var checkStatus = layui.table.checkStatus(bussId);
        var data = checkStatus.data;
        if (data.length > 0) {
            if (data.length == 1) {
                layer.open({
                    id: "formRenderingHtml5",
                    type: 2,
                    title: '添加用户',
                    shadeClose: true,
                    shade: [0.6, '#FFF'],
                    area: ['700px', '70%'],
                    content: './formRendering.html?id=5&userId=' + data[0].userId // iframe 的 url
                });
            } else {
                layui.kaMsg.error("只能选取一条数据");
            }
        } else {
            layui.kaMsg.error("请选取一条数据");
        }
    },
    update: function (bussId, type) { // 更新
        if (type == 0) {
            var checkStatus = layui.table.checkStatus(bussId);
            var data = checkStatus.data;
            if (data.length > 0) {
                if (data.length == 1) {
                    layer.open({
                        id: "formRenderingHtml5",
                        type: 2,
                        title: '添加用户',
                        shadeClose: true,
                        shade: [0.6, '#FFF'],
                        area: ['700px', '70%'],
                        content: './formRendering.html?id=5&userId=' + data[0].userId // iframe 的 url
                    });
                } else {
                    layui.kaMsg.error("只能选取一条数据");
                }
            } else {
                layui.kaMsg.error("请选取一条数据");
            }
        } else if (type == 2) {
            layer.open({
                id: "formRenderingHtml5",
                type: 2,
                title: '添加用户',
                shadeClose: true,
                shade: [0.6, '#FFF'],
                area: ['700px', '70%'],
                content: './formRendering.html?id=6&userId=' + bussId // iframe 的 url
            });
        }
    },
    delete: function (bussId, type) { // 删除
        if (type == 0) {
            var checkStatus = layui.table.checkStatus(bussId);
            var data = checkStatus.data;
            var userIds = "";
            var userIdArrays = [];
            if (data.length > 0) {
                layer.confirm('确定删除吗？', { icon: 3 }, function () {
                    for (var i in data) {
                        userIdArrays.push(data[i].userId);
                    }
                    userIds = userIdArrays.join(",");
                    layui.kaAjax.ajax(layui.kaBgUrl.url("userRemove"), function (rs) {
                        if (rs.code == 200) {
                            layui.kaGridSearch.init('kaDataGridId');
                            layui.layer.closeAll();
                            layui.kaMsg.success("删除成功！", "1");
                        }
                    }, { "userIds": userIds });
                }, function () {
                    layer.msg('已经取消');
                });
            } else {
                layui.kaMsg.error("请选取一条数据");
            }
        } else if (type == 2) {
            layer.confirm('确定删除吗？', { icon: 3 }, function () {
                layui.kaAjax.ajax(layui.kaBgUrl.url("userRemove"), function (rs) {
                    if (rs.code == 200) {
                        layui.kaGridSearch.init('kaDataGridId');
                        layui.layer.closeAll();
                        layui.kaMsg.success("删除成功！", "1");
                    }
                }, { "userIds": bussId });
            }, function () {
                layer.msg('已经取消');
            });
        }
    },
    showEyepPhonenumberOrEmail: function (divId, id, type) {
        var $ = layui.$;
        var classStr = $("#" + divId + "_eye").attr("class");
        var str = "";
        if (type == 1) { // 手机号码
            if (classStr.indexOf("Kaultraicon-yanjing_yincang_o") == -1) { // 显示
                str = "显示11111";
            } else { // 隐藏
                const reg = /(\d{3})\d{4}(\d{4})/;
                str = String("18970566375").replace(reg, "$1****$2")
            }
        } if (type == 2) { // 邮箱
            if (classStr.indexOf("Kaultraicon-yanjing_yincang_o") == -1) { // 显示
                str = "显示11111222";
            } else { // 隐藏
                var email = "188888888@qq.com";
                var arr = email.split("@");
                var star = "";
                if (arr[0].length <= 3) {
                    star = "*";
                    arr[0] = arr[0].substr(0, arr[0].length) + star;
                } else {
                    star = "***";
                    arr[0] = arr[0].substr(0, 1) + star + arr[0].charAt(arr[0].length - 1);
                }
                str = arr[0] + "@" + arr[1];
            }
        }
        // 处理 I
        if (classStr.indexOf("Kaultraicon-yanjing_yincang_o") == -1) { // 显示
            $("#" + divId + "_eye").attr("class", "icon Kaultraiconfont Kaultraicon-yanjing_yincang_o");
        } else { // 隐藏
            $("#" + divId + "_eye").attr("class", "icon Kaultraiconfont Kaultraicon-yanjing");
        }
        $("#" + divId).html(str);
    }
}